package com.qidian.by.goods.controller;

import com.qidian.by.goods.service.IItemService;
import com.qidian.by.goods.service.feign.FreeTemplateClient;
import com.qidian.by.util.pojo.EsResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @Author: CoolPro
 * @Description:
 * @Time: 2024-05-17 08:44
 **/
@Controller
public class ItemFreeController {

    @Resource
    private FreeTemplateClient freeTemplateClient;
    @Resource
    private IItemService itemService;


    @GetMapping("/free")
    public void getFree(HttpServletResponse response, Long itemId) {
        EsResult itemInfoById = itemService.getItemInfoById(itemId);
        freeTemplateClient.make(EsResult.object2json(itemInfoById));
        response.setStatus(302);
        String url = "http://item.easyby.com:6500/" +itemId+".html";
        response.setHeader("Location", url);
    }
}
